package ufc.web.funcoes;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ufc.web.conexaoBD.ConnectionFactory;

public class DeletaLivros implements Acao{

 public int deletar(String isbn) {
	 
	 	int res = 1;
		try{
			String consulta = "delete from livro where ISBN=?";
			Connection con = ConnectionFactory.getConnection();
			PreparedStatement ps = con.prepareStatement(consulta);
			ps.setString(1, isbn);
			
			res = ps.executeUpdate();
			con.close();
			ps.close();
			}catch(SQLException e){			
				System.out.println(e.getMessage());

			}
		
		return res;
	 
}

@Override
public void executa(HttpServletRequest request, HttpServletResponse response) {
	
	deletar(request.getParameter("campo"));
	
	try {
		response.sendRedirect("Administrador.jsp?user=3&&resultado=1");
		
	} catch (IOException e) {
		e.printStackTrace();
	}
}


}
